home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / SanFrancisco_1989 / SF-Devcon89.2 / Workbench / AppWindow / appwindow.c
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.6 KB  |  115 lines

  1. /*
  2.     Code to test AppWindow feature of Workbench.
  3. */
  4.  
  5. #include <intuition/intuition.h>
  6. #include <workbench/startup.h>
  7. #include "workbench/workbench.h"
  8.  
  9. #define INTUITIONNAME    "intuition.library"
  10. #define WORKBENCHNAME    "workbench.library"
  11.  
  12. struct IntuitionBase *IntuitionBase = NULL;
  13. struct WorkbenchBase *WorkbenchBase = NULL;
  14.  
  15. struct NewWindow nw = {
  16.     0, 0,        /* leftedge, topedge */
  17.     160,50,        /* width, height */
  18.     -1, -1,        /* DetailPen, BlockPen */
  19.     CLOSEWINDOW,        /* IDCMP flags */
  20.     WINDOWCLOSE|WINDOWDRAG,        /* flags */
  21.     NULL,        /* FirstGadget */
  22.     NULL,        /* Image */
  23.     "AppWindow",    /* Title */
  24.     NULL,        /* Screen */
  25.     NULL,        /* BitMap */
  26.     0, 0,        /* MinWidth, MinHeight */
  27.     0, 0,        /* MaxWidth, MaxHeight */
  28.     WBENCHSCREEN    /* type */
  29. };
  30.  
  31. main(argc, argv)
  32. int argc;
  33. char **argv;
  34. {
  35.     void *OpenLibrary();
  36.     struct MsgPort *CreatePort();
  37.     struct Window *OpenWindow();
  38.     struct IntuiMessage *GetMsg();
  39.     struct AppWindow *AddAppWindow();
  40.  
  41.     struct MsgPort *msgport = NULL;
  42.     struct Window *win = NULL;
  43.     struct AppWindow *aw = NULL;
  44.     struct IntuiMessage *imsg;
  45.     struct AppMessage *amsg;
  46.     struct WBArg *argptr;
  47.     ULONG userdata = 0;
  48.     ULONG id = 1;
  49.     BOOL done = FALSE;
  50.     int i;
  51.  
  52.     printf("aw: enter\n");
  53.     if (!(IntuitionBase = OpenLibrary(INTUITIONNAME, 0))) {
  54.         printf("aw: could not open intuition\n");
  55.         goto err;
  56.     }
  57.     if (!(WorkbenchBase = OpenLibrary(WORKBENCHNAME, 36))) {
  58.         printf("aw: could not open workbench\n");
  59.         goto err;
  60.     }
  61.     if (!(msgport = CreatePort("appwindow", 0))) {
  62.         printf("aw: could not createport\n");
  63.         goto err;
  64.     }
  65.     if (!(win = OpenWindow(&nw))) {
  66.         printf("aw: could not openwindow\n");
  67.         goto err;
  68.     }
  69.     printf("aw: calling AddAppWindow...", win);
  70.     if (!(aw = AddAppWindow(id, userdata, win, msgport))) {
  71.         printf("aw: could not addappwindow\n");
  72.         goto err;
  73.     }
  74.     printf("aw: ok, aw = %lx, going to sleep\n", aw);
  75.     do {
  76.         Wait((1 << win->UserPort->mp_SigBit) |
  77.             (1 << msgport->mp_SigBit));
  78.         while (imsg = GetMsg(win->UserPort)) {
  79.             if (imsg->Class == CLOSEWINDOW) {
  80.                 done = TRUE;
  81.             }
  82.         };
  83.         while (amsg = GetMsg(msgport)) {
  84.             printf("aw: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n", amsg, amsg->am_Type, amsg->am_ID, amsg->am_UserData, amsg->am_NumArgs);
  85.             argptr = amsg->am_ArgList;
  86.             for (i=0; i<amsg->am_NumArgs; i++) {
  87.                 printf("\targ(%ld): Name='%s', Lock=%lx\n",
  88.                 i, argptr->wa_Name, argptr->wa_Lock);
  89.                 argptr++;
  90.             }
  91.             ReplyMsg(amsg);
  92.         };
  93.     } while (!done);
  94.  
  95.     if (aw) {
  96.         printf("aw: calling RemoveAppWindow\n");
  97.         RemoveAppWindow(aw);
  98.     }
  99.  
  100. err:
  101.     if (win) {
  102.         CloseWindow(win);
  103.     }
  104.     if (msgport) {
  105.         DeletePort(msgport);
  106.     }
  107.     if (WorkbenchBase) {
  108.         CloseLibrary(WorkbenchBase);
  109.     }
  110.     if (IntuitionBase) {
  111.         CloseLibrary(IntuitionBase);
  112.     }
  113.     printf("aw: exit\n");
  114. }
  115.